home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDIdent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  3.8 KB  |  143 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDIdent - An XFCN to return an unique number identifying this disc
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDIdent.c
  11.     link -sn Main=CDIdent -sn STDIO=CDIdent ∂
  12.          -sn INTENV=CDIdent -rt XFCN=42 ∂
  13.          -m CDIDENT CDIdent.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. OSErr    IDDisc(short, unsigned long *);
  28. OSErr    ReadQ(short, short *, short *, short *, short *);
  29.  
  30. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  31.  
  32.  
  33. /************************************************************************
  34.  *
  35.  *  Function:        CDIdent
  36.  *
  37.  *  Purpose:        return an unique number for this disc.
  38.  *
  39.  *  Returns:        either the unique number, or an error
  40.  *                    if it's a negative number, it's an error
  41.  *                    if we return nothing, wrong number of parameters
  42.  *                    were specified.
  43.  *
  44.  *  Side Effects:
  45.  *
  46.  *  Description:    We need no parameters
  47.  *                    Get the ioRefNum that we got from previously calling
  48.  *                    CDOpen(), by accessing the famous global.
  49.  *                    call ThisDisc() to get a the lead-out minutes, seconds,
  50.  *                    and blocks.  Add all these together to get the total
  51.  *                    number of blocks on this disc.  This is as unique as
  52.  *                    we can get, since it's difficult to press two CDs
  53.  *                    that are equal to 1/75th of a second.
  54.  *
  55.  ************************************************************************/
  56. pascal void
  57. CDIdent(paramPtr)
  58. XCmdBlockPtr    paramPtr;
  59. {
  60.     Str31    returnString;
  61.     OSErr    result;
  62.     short    ioRefNum;
  63.     Handle    refHandle;
  64.     unsigned long    discID;
  65.     
  66.     /* Must be no parameter */
  67.     if ((paramPtr->paramCount) != 0)
  68.     {
  69.         /* Report error in parameters by returning -1 */
  70.         NumToStr(paramPtr, -1L, (Str31 *)returnString);
  71.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  72.         return;
  73.     }
  74.     
  75.     /* Get the global ioRefNum and convert it. */
  76.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  77.     ioRefNum = atoi(*(refHandle));
  78.     DisposHandle(refHandle);
  79.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  80.     
  81.     
  82.     result = IDDisc(ioRefNum, &discID);
  83.         
  84.     if (result == noErr)
  85.     {
  86.         /* Convert id to string & return it as result */
  87.         NumToStr(paramPtr, discID, (Str31 *)returnString);
  88.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) returnString);
  89.     }
  90.     else
  91.     {
  92.         /* We got an error. Convert result to string & return it as error */
  93.         NumToStr(paramPtr, (long) result, (Str31 *)returnString);
  94.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) returnString);
  95.     }
  96. }
  97.  
  98.  
  99. /************************************************************************
  100.  *
  101.  *  Function:        IDDisc
  102.  *
  103.  *  Purpose:        return total time on this disc as unique ID
  104.  *
  105.  *  Returns:        OSErr
  106.  *                    either noErr if everything was okay
  107.  *                    or some parameter error from driver call.
  108.  *
  109.  *  Side Effects:
  110.  *                    fills in discID
  111.  *
  112.  *  Description:
  113.  *                    call the driver ReadTOC call to get lead-out time.
  114.  *                    Return this time as the unique id for this disc.
  115.  *
  116.  ************************************************************************/
  117. OSErr
  118. IDDisc(refNum, discID)
  119. short    refNum;
  120. unsigned long    *discID;
  121. {
  122.     CDIDParam    myPB;
  123.     OSErr    result;
  124.     
  125.     myPB.ioCompletion = 0;
  126.     myPB.ioNamePtr = (char *) 0;
  127.     myPB.ioVRefNum = 1;
  128.     myPB.ioCRefNum = refNum;
  129.     myPB.csCode = READTOC;
  130.     myPB.discID = 0x00020000;    /* request lead-out time */
  131.     
  132.     result = PBControl((ParmBlkPtr)&myPB, false);
  133.     
  134.     if (result == noErr)
  135.         *discID = myPB.discID >> 8;
  136.     else
  137.         *discID = 0;
  138.     return result;
  139. }
  140.  
  141. /* C routines for HyperCard callbacks */
  142. #include <XCmdGlue.inc.c>
  143.